import * as THREE from 'three';
import type Viewer from '../Viewer';
import { Water } from 'three/examples/jsm/objects/Water.js';


/** 水面场景*/
export default class WaterGeometry {
  protected viewer: Viewer;
  protected water: any;
  constructor (viewer: Viewer) {
    this.viewer = viewer;
  }

  /**
   * 添加水面
   */
  private setWaterGeomety () {
    const waterGeometry = new THREE.PlaneGeometry(10000, 10000);
    this.water = new Water(
      waterGeometry,
      {
        textureWidth: 512,
        textureHeight: 512,
        waterNormals: new THREE.TextureLoader().load('/water.jpeg', function (texture) {
          texture.wrapS = texture.wrapT = THREE.RepeatWrapping;
        }),
        sunDirection: new THREE.Vector3(),
        sunColor: 0xffffff,
        waterColor: 0x294f9a,
        distortionScale: 3.7,
      }
    );
    this.water.rotation.x = - Math.PI / 2;
    this.viewer.scene.add(this.water)
  }

  private waterAction () {
    this.water.material.uniforms["time"].value += 1.0 / 60.0;
  }
}
